{include file="public/header"/}
<div id="container">

  <div style="line-height: 30px;background-color: #FFF9E3;border: 1px solid #F8F1D7;color: #BF862D;padding: 0 10px; width: 98%;margin: 10px auto;">
    每添加或删除分组，都需要再次去生成新的前端部署代码
  </div>
   <div id="page-header" class="am-cf" style="position: absolute;top: 2px;right: 13px;">

        <div class="button">
            <a href="javascript:add()" class="am-btn am-btn-xs am-btn-primary" data-pjax><i class="am-icon-plus"></i> 添加分组</a>
        </div>
    </div>
    <section class="panel" style="width: 98%;margin: 5px auto;">
     <table class="table">
            <thead>
            <tr>
                <th>分组名</th>
                <th>短信內容</th>
                <th>操作</th>
            </tr>
            </thead>
            <tbody>
                {volist name='group' id='g'}
                <tr>
                	<td>{$g.groupname}</td>
                    <td><input type="text" value="{$g.comment}" style="width:30em" id="link-{$g.id}"/>&nbsp;&nbsp;<a
                            href='javascript:copylink("link-{$g.id}")' class='am-badge am-badge-primary'>复制</a></td>
                	<td>
                        <a onclick="getdelete({$g.id})" class='am-badge am-badge-danger'> <i class='am-icon-recycle'></i> 删除</a>
                        <a href='javascript:guanli({$g})' class='am-badge am-badge-primary'>
                            <i class='am-icon-edit'></i> 编辑</a>
                    </td>
                </tr>
                {/volist}
            </tbody>
        </table>
        {$page}
   </section>
</div>
<script>
	
	 var getdelete =function(id){

        $.ajax({
            url:'/admin/manager/delclass',
            type:'post',
            data:{cid:id},
            success:function(res){
                  
                  if(res.code == 0){
                    layer.msg(res.msg,{icon:1,end:function(){
                        location.reload();
                    }}); 
                  }else{
                     layer.msg(res.msg,{icon:2}); 
                  }
            }
        });
    }

   function add(){
   	var html  ='';
   	    html +='<form class="layui-form" style="margin-top:30px;">';
   	    html +='<div class="layui-form-item"><label class="layui-form-label">分组名:</label>';
   	    html +='<div class="layui-input-block">';
   	    html +=' <input type="text" id="classname" required placeholder="请输入分组名" autocomplete="off" class="layui-input" style="width:260px;"></div>';
   	    html +='</div></form>';

   	  layer.open({
   	  	type:1,
   	  	title:'添加分组',
   	  	area:['400px','180px'],
   	  	content:html,
   	  	btn: ['提交', '取消'],
   	  	yes:function(){

            var name =$("#classname").val().trim();
            if(name){

		         $.ajax({
		          url:'{:url("admin/manager/addclass")}',
		          type:'post',
		          data:{groupname:name},
		          dataType:'json',
		          success:function(res){

		             if(res.code == 0){
		                layer.msg(res.msg,{icon:1,end:function(){
		                    location.reload();
		                }});
		             }else{
		                layer.msg(res.msg,{icon:2});
		             }
		          }
		     });
		         
		    }else{
		          
		       layer.msg('分组名不能为空',{icon:2});   
		    }
		    

   	  	}
   	  })
   }

     function copylink(id) {
         var Input = $('#' + id);
         Input.focus();
         Input.select();
         try {
             document.execCommand('copy');
             layer.msg('复制成功', {time: 1000});
         } catch (e) {
             console.log(e);
             layer.msg('复制失败', {time: 1000});
         }
     }


</script>

{include file="public/footer"/}
